package com.ruoyi.ldzlsc.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ldzlsc.domain.ScSalesOrder;
import com.ruoyi.ldzlsc.domain.ScSalesOrderDetail;
import com.ruoyi.ldzlsc.service.ScSalesOrderService;

/**
 * 销售订单Controller
 *
 * @author ldzl
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/sc/salesOrder")
public class ScSalesOrderController extends BaseController {
    @Autowired
    private ScSalesOrderService scSalesOrderService;

    /**
     * 查询销售订单列表
     */
    //@RequiresPermissions("sc:salesOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(ScSalesOrder scSalesOrder) {
        startPage();
        List<ScSalesOrder> list = scSalesOrderService.selectScSalesOrderList(scSalesOrder);
        return getDataTable(list);
    }
    
    /**
     * 查询销售订单明细列表
     */
    //@RequiresPermissions("sc:salesOrder:query")
    @GetMapping("/detail/{salesOrderId}")
    public TableDataInfo detail(@PathVariable("salesOrderId") Long salesOrderId) {
        startPage();
        List<ScSalesOrderDetail> list = scSalesOrderService.selectScSalesOrderDetailList(salesOrderId);
        return getDataTable(list);
    }
    
    /**
     * 获取销售订单详细信息
     */
    //@RequiresPermissions("sc:salesOrder:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(scSalesOrderService.selectScSalesOrderById(id));
    }

    /**
     * 新增销售订单
     */
    //@RequiresPermissions("sc:salesOrder:add")
    @Log(title = "销售订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScSalesOrder scSalesOrder) {
        return toAjax(scSalesOrderService.insertScSalesOrder(scSalesOrder));
    }

    /**
     * 修改销售订单
     */
    //@RequiresPermissions("sc:salesOrder:edit")
    @Log(title = "销售订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScSalesOrder scSalesOrder) {
        return toAjax(scSalesOrderService.updateScSalesOrder(scSalesOrder));
    }

    /**
     * 删除销售订单
     */
    //@RequiresPermissions("sc:salesOrder:remove")
    @Log(title = "销售订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scSalesOrderService.deleteScSalesOrderByIds(ids));
    }
} 